/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        vector<vector<int>> ret;
        queue<Node*> q;

        if (root == nullptr)
            return ret;

        q.push(root);
        while (!q.empty())
        {
            int n = q.size();
            vector<int> v;
            while (n--)
            {
                v.push_back(q.front()->val);
                for (auto x : q.front()->children)
                    q.push(x);

                q.pop();
            }
            ret.push_back(v);
        }

        return ret;
    }
};